import { createRootVnode } from "./vnode";

/**
 * 创建app实例
 * @param render 渲染函数
 * @returns
 */
export function createAppAPI(render) {
  return function createApp(rootContainer) {
    let isMounted = false;
    const app = {
      mount(rootContainer: Element) {
        if (isMounted) {
          console.error("app 已经挂载");
          return;
        }

        const vnode = createRootVnode(rootContainer);

        render(vnode, rootContainer);

        isMounted = true;
      },
    };
    return app;
  };
}
